//
//  LoveViewController.m
//  掌厨
//
//  Created by aoyolo on 15/10/22.
//  Copyright (c) 2015年 李祖铜. All rights reserved.
//

#import "LoveViewController.h"
#import "AFNetworking.h"

#import "LikeModel.h"

#import "LikeCell.h"


@interface LoveViewController ()<UITableViewDataSource, UITableViewDelegate>
{
    UIWebView *_likeWebView;
    UIButton *_backBtn;
}

@property (weak, nonatomic) IBOutlet UITableView *tableView;


@property (nonatomic, strong)NSMutableArray *loves;

@end

@implementation LoveViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _loves = [NSMutableArray array];
    
    //段尾页
    [self setLoveTall];
    
    self.navigationController.navigationBar.barTintColor = appColor;
    //设置导航栏标题的字体颜色和大小
    self.navigationItem.title = @"喜欢";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15], NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    //注册cell
    [_tableView registerNib:[UINib nibWithNibName:@"LikeCell" bundle:nil] forCellReuseIdentifier:@"LikeCellId"];
    
    //喜欢页面POST请求
    AFHTTPRequestOperationManager *likeStr = [AFHTTPRequestOperationManager manager];
    [likeStr POST:zhangchuURL parameters:@{@"methodName":@"UserLikes", @"page":@"1", @"size":@"10", @"token":@"0", @"user_id":@"0", @"version":@"1.0"} success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSArray *str = responseObject[@"data"][@"data_recomment"];
        
        for (NSDictionary *dic in str)
        {
            LikeModel *model = [[LikeModel alloc]init];
            model.title = dic[@"title"];
            model.descrip = dic[@"description"];
            model.image = dic[@"image"];
            model.video = dic[@"video"];
            [self.loves addObject:model];
            
        }
        
        [self.tableView reloadData];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
    
}

//- (void)buttonLikeDidcheak:(NSString*)LikefishName
//{
//    _likeWebView = [[UIWebView alloc]initWithFrame:self.view.bounds];
//    _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    [_backBtn setFrame:CGRectMake(0, self.view.bounds.size.height- 650, 80, 30)];
//    [_backBtn setTitle:@"完成" forState:UIControlStateNormal];
//    [_backBtn addTarget:self action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];
//    [_likeWebView addSubview:_backBtn];
//    
//    _likeWebView.scalesPageToFit = YES;//自动对页面进行缩放以适应屏幕
//    LoveViewController *viewCtl = [[LoveViewController alloc]init];
//    [viewCtl.view addSubview:_likeWebView];
//    for (LikeModel *mode in _loves) {
//        if ([mode.title isEqualToString:LikefishName]) {
//            [_likeWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:mode.video]]];
//            [self presentViewController:viewCtl animated:YES completion:nil];
//        }
//    }
//    
//}
//
//#pragma mark - 实现视频播放器返回方法
//-(void)goBack:(id)sender
//{
//    [self dismissViewControllerAnimated:YES completion:nil];
//}




#pragma mark - UITableViewDataSource
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 170;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _loves.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LikeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LikeCellId"];
//    cell.delegate = self;
    [cell setLove:[self.loves objectAtIndex:indexPath.section]];
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10.0;
}
     
-(void)setLoveTall
{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 200)];
    //设置tableView的尾视图，有且只有一个
    _tableView.tableFooterView = view;
    view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    UIButton *btn = [[UIButton alloc]init];
    btn.frame = CGRectMake(80, 30, 210, 35);
    btn.backgroundColor = [UIColor orangeColor];
    [btn setTitle:@"登录下，让掌厨更懂你" forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:15];
    [btn setImage:[UIImage imageNamed:@"guide"] forState:UIControlStateNormal];
    
    btn.imageEdgeInsets = UIEdgeInsetsMake(0, 190, 0, 0);
    btn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 30);//图片文字添加混编偏移调整
    
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn];
    
}
- (void)btnClick:(UIButton *)sender
{
    NSLog(@"点击");
}






@end
